<!doctype  html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
	<title>学术竞赛</title>
<style type="text/css">
       body{
               background: url("image/6_bg.png");
               background-size: 100% 100%;
               background-repeat: no-repeat;
               min-height:1000px;
               width: 100%;
               padding-bottom:30px;
       }
       form{
       	margin: 0 auto;
       	margin-top:50px;
       	width: 700px;
       	position: relative;
       }
       select{
       	width: 150px;
        height: 20px;
       	margin: 0 auto;
       	position: absolute;
       	left: 275px;
       }
       .input{
       	   width: 200px;

       }
      .span{
       	   display: inline-block;
       	   width: 90px;
       	   margin-top: 25px;
       }
       .moveright{
       	   margin-left: 30px;
       }
       .center{
       	   margin-left:250px;
       }

       #intro{
        resize:none;
        height:75px;
        width:600px;
        margin-left: 50px;
        margin-top: 15px;
       }
       #textarea{
       	resize:none;
       	height:300px;
       	width:700px; 
        position: relative;
       }
       .button{
       	   display: inline-block;
       	   margin-top: 30px;
       	   height: 28px;
       	   width: 80px;
       	   margin-right:15px;
       	   float:right;
       	   line-height: 25px;

       }
    
</style>
</head>
<body>
	<form>
            <select>
		           <option>栏目ID</option>
		           <option>第一届</option>
		           <option>第二届</option>
		           <option>第三届</option>
		 	</select><br>
		     <span class="span" >编辑：</span><input class="input" type="text" name="editor" id="editor">
		     <span class="span moveright">标题：</span><input class="input" type="text" name="title" id="title"><br>
		     <span class="span">类别：</span><input class="input" type="text" name="type" id="type">
		     <span class="span moveright">级别：</span><input class="input" type="text" name="jibie" id="jibie"><br>
		     <span class="span">第一作者：</span><input class="input" type="text" name="author" id="author">
		     <span class="span moveright" >专业：</span><input class="input" type="text" name="major" id="major">
		     <span class="span" >作者团队：</span><input class="input" type="text" name="team" id="team">
		     <span class="span moveright">年级：</span><input class="input" type="text" name="grade" id="grade"><br>
		     <span class="span">简介：</span><br><textarea rols="10" rows="5" id="intro"></textarea><br>       
         <span class="span" style="margin-bottom:10px;">图片：</span><br>
		     <textarea rols="10" rows="5" id="textarea"></textarea>
		     <span style="position:relative;top:15px;">赞次数：</span><input type="number" name="number" id="likeTimes" style="position:relative;top:15px;">
		     <span style="position:relative;top:15px;">状态：</span><input type="checkbox" name="checkbox" id="status" style="position:relative;top:15px;"><br>
		     <input type="button" class="button" id="submit" value="提交">
		     <a class="button" style="position:relative;left:20px;top:3px;" href="content_mag.html">返回</a>
	</form>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script charset="utf-8" src="js/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript" src="js/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript" src="../public/js/serverIp.js"></script>
<script type="text/javascript">
        var editor;
        KindEditor.ready(function(K){
        	 K.create("#textarea",{
  				     uploadJson : 'js/kindeditor/php/upload_json.php', //指定上传图片的服务器端程序
  				     allowUpload : true,
  					   fileManagerJson:"jskindeditor/php/file_manager_json.php",
  					   allowFileManager : true,
  				     urlType : 'absolute',
  				      resizeType : 0,  //文本框不可拖动
				        
				        afterCreate : function(){ //kindeditor创建后，将编辑器的内容设置到原来的textarea控件里
				               this.sync();   
				        },
				        afterChange: function(){ //编辑器内容发生变化后，将编辑器的内容设置到原来的textarea控件里
				               this.sync();   
				        },
				        afterBlur : function(){ //编辑器聚焦后，将编辑器的内容设置到原来的textarea控件里
				            this.sync(); 
				        }  
		       })

         })

        var array=window.location.href.split("?");
        var substr=array[1].split("&");
        var datastr="type=ID&bool=false&columnId="+substr[1]+"&modelId="+substr[0]+"&id="+substr[3];
        if(substr[2]=="edit"){
            $.post(serverIp+"/Scauaie.com/artical/showAll",datastr,function(data){
              
                 KindEditor.html('#textarea',data[0].picture);//给文本框内赋值
                 $("#editor").val(data[0].editor);
                 $("#title").val(data[0].title);
                 $("#type").val(data[0].kind);
                 $("#jibie").val(data[0].level);
                 $("#author").val(data[0].firstAuthor);
                 $("#major").val(data[0].profession);
                 $("#team").val(data[0].team);
                 $("#grade").val(data[0].grade);
                 $("#intro").val(data[0].intro);
                 $("#poster").val(data[0].poster);
                 $("#likeTimes").val(data[0].likeTimes);
                 data[0].status==true?$("#status").attr("checked",true):null;
            },"json")

        }


        function submitTo(url,id){

              var arr=window.location.href.split("?");
              var sub=arr[1].split("&");
              var time="2016/4/14";
              var editor=$("#editor").val();
              var title=$("#title").val();
              var type=$("#type").val();
              var jibie=$("#jibie").val();
              var author=$("#author").val();
              var major=$("#major").val();
              var team=$("#team").val();
              var grade=$("#grade").val();
              var intro=$("#intro").val();
              // var poster="img";
              var posters=$("#textarea").val().match(/(\/\w+)+\.jpg|\.png|\.jpeg|\.gif/i);
              var poster=posters[0];
              var content=$("#textarea").val();
              var likeTimes=$("#likeTimes").val();
              var status=$("#status").attr("checked")=="checked"?true:false;  
              var data={
                    "type":"COLUMN",
                    "bool":false,
                    "modelId":sub[0],
                    "columnId":sub[1],
                    "editor":editor,
                    "title":title,
                    "kind":type,
                    "level":jibie,
                    "firstAuthor":author,
                    "profession":major,
                    "team":team,
                    "grade":grade,
                    "intro":intro,
                    "poster":poster,
                    "picture":content,
                    "likeTimes":likeTimes,
                    "status":status,
                    "id":id,
                    "work_id":id
                };


               if(!editor||!title||!type||!jibie||!author||!major||!team||!grade||!intro||!poster||!content||!likeTimes){
                      alert("请先填写完整");
               }else{
                  $.post(url,{"data":JSON.stringify(data)},function(data){
                        var dataobj=JSON.parse(data);
                        if(dataobj.bool=="true"){
                            if(confirm("提交成功，留在本页面？")){
                               var href=window.location.href;
                                window.location.href=href;
                            }else{
                               window.location.href="content_mag.html";
                            }
                        }else{
                           alert("提交失败,请重新尝试") ;                         
                        } 

                   },"html")
               }
        }

          $("#submit").click(function(){               
                if(substr[2]=="edit"){
                  submitTo(serverIp+"/Scauaie.com/artical/edit",substr[3]);

               }else{
                   submitTo(serverIp+"/Scauaie.com/artical/add",null);
                }  
          })
</script>
</body>
</html>	